package com.xinxin.websocket.service.impl;

import com.xinxin.websocket.dao.UserRepository;
import com.xinxin.websocket.dataobject.User;
import com.xinxin.websocket.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：史鑫鑫
 * @date ：Created in 2019/4/29 18:14
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserRepository repository;

    @Override
    public void insert(User user) {
        if (repository.findByName(user.getName()) == null) {
            System.out.println("新建一条数据");
            repository.save(user);
        }
    }

    @Override
    public User findByName(String name) {
        System.out.println("查找用户");
        return repository.findByName(name);
    }

    @Override
    public void update(User user) {
        if (repository.findByName(user.getName()) != null) {
            System.out.println("更新数据");
            repository.save(user);
        }
    }
}
